﻿package com.red.battleworm {
	import com.red.battleworm.controller.*;
	import com.gudogudo.battleworm.model.*;	
	
	import org.puremvc.as3.patterns.facade.Facade;

	import flash.display.*;

	/**
	 * @author Administrator
	 */
	public class AppMain extends Facade {
		public static var root : Sprite;
		public static var stage : Stage;

		public static const STARTUP:String = "startup";
		public static const RESTART:String = "restart";
		
		//交互命令
		public static const LOGIN:String = "LOGIN";
		public static const VALIDATE:String = "VALIDATE";
		public static const ENTERGAME:String = "ENTERGAME";
		public static const INITGAME:String = "INITGAME";
		public static const INITREADY:String = "INITREADY";
		public static const STARTGAME:String = "STARTGAME";
		public static const ENDROUNDOP:String = "ENDROUNDOP";
		public static const STARTSIMULATE:String = "STARTSIMULATE";
		public static const ENDSIMULATE:String = "ENDSIMULATE";
		public static const ENDROUND:String = "ENDROUND";
		public static const QUITGAME:String = "QUITGAME";
		public static const QUITCOMPLETE:String = "QUITCOMPLETE";
		
		//界面显示命令
		public static const SHOWLOGIN:String = "SHOWLOGIN";
		public static const SHOWROOM:String = "SHOWROOM";
		
		//MODEL
		public static const GAMEPROXY:String = "GAMEPROXY";

		public static function getInstance() : AppMain {
            if ( instance == null ) instance = new AppMain( );
            return instance as AppMain;
        }
        
        override protected function initializeController( ) : void 
        {
            super.initializeController();
            //交互命令注册
            registerCommand( STARTUP, StartUpCmd );
            registerCommand( LOGIN, LoginCmd );
//            registerCommand( VALIDATE, ValidateCmd );
            registerCommand( ENTERGAME, EnterGameCmd );
            registerCommand( INITGAME, InitGameCmd );
            registerCommand( INITREADY, InitReadyCmd );
            registerCommand( STARTGAME, StartGameCmd );
            registerCommand( ENDROUNDOP, EndRoundOpCmd );
            registerCommand( STARTSIMULATE, StartSimulateCmd );
            registerCommand( ENDSIMULATE, EndSimulateCmd );
            registerCommand( ENDROUND, EndRoundCmd );
            registerCommand( QUITGAME, QuitGameCmd );
            registerCommand( QUITCOMPLETE, QuitCompleteCmd );
        }

		protected override function initializeModel() : void {
			super.initializeModel();
			
			registerProxy(new GameProxy(GAMEPROXY));
		}

		public function startup( root : Sprite ) : void {
			AppMain.root = root;
			AppMain.stage = root.stage;
			AppMain.stage.scaleMode=StageScaleMode.NO_SCALE;
        	sendNotification( STARTUP, stage );
        }
	}
}
